package com.shop.item.atom.atomsvc.impl;

import com.shop.common.model.ServiceBean;
import com.shop.common.model.param.item.ItemLabelInput;
import com.shop.common.model.param.item.LabelInput;
import com.shop.common.model.result.item.LabelOutput;
import com.shop.common.tmpl.BaseService;
import com.shop.item.atom.atomsvc.ILabelAtomService;
import com.shop.item.atom.dao.ItemLabelMapper;
import com.shop.item.atom.dao.LabelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhoulk
 * @Description: 标签服务
 * @date: 2019年03月24日  17:10
 */
@Service
public class LabelAtomService extends BaseService implements ILabelAtomService {
    @Autowired
    private LabelMapper labelMapper;
    @Autowired
    private ItemLabelMapper itemLabelMapper;

    @Override
    public ServiceBean<List<LabelOutput>> getLabelList(LabelInput labelInput) {
        List<LabelOutput> list = labelMapper.selectList(labelInput);
        if (list == null || list.size() <= 0) {
            return resultFailed();
        }
        return resultData(list);
    }

    @Override
    public ServiceBean<LabelOutput> selectLabelBySelective(LabelInput labelInput) {
        LabelOutput labelOutput = labelMapper.selectSelective(labelInput);
        if (labelOutput != null) {
            return resultData(labelInput);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<List<LabelOutput>> selectLabelByNames(List<String> names) {
        List<LabelOutput> labelOutputs = labelMapper.selectByNames(names);
        if (labelOutputs != null && labelOutputs.size() > 0) {
            return resultData(labelOutputs);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<Integer> insertLabelList(List<ItemLabelInput> labelInputs) {
        Integer num = itemLabelMapper.insertList(labelInputs);
        if (opSuccess(num)) {
            return resultSuccess();
        }
        return resultFailed();
    }
}
